/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entities;

import java.sql.Date;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author yoshi
 */
public class EmployeeShiftRequest {

    private long id;
    private long fromScheduleId;
    private long employeeId;
    private Date requestDate;
    private long timeSlotId;
    private String note;
    private short status;
    private TimeSlot timeSlot;
    private EmployeeSchedule fromSchedule;
    private Employee employee;

    public EmployeeShiftRequest(ResultSet rs) {
        this.loadFromResultSet(rs);
    }

    public EmployeeShiftRequest(long id, long fromScheduleId, long employeeId, Date requestDate, long TimeSlotId, String note, short status) {
        this.id = id;
        this.fromScheduleId = fromScheduleId;
        this.employeeId = employeeId;
        this.requestDate = requestDate;
        this.timeSlotId = TimeSlotId;
        this.note = note;
        this.status = status;
    }

    public long getTimeSlotId() {
        return timeSlotId;
    }

    public void setTimeSlotId(long TimeSlotId) {
        this.timeSlotId = TimeSlotId;
    }

    public EmployeeSchedule getFromSchedule() {
        return fromSchedule;
    }

    public void setFromSchedule(EmployeeSchedule fromSchedule) {
        this.fromSchedule = fromSchedule;
        this.fromScheduleId = fromSchedule.getId();
    }

    public long getFromScheduleId() {
        return fromScheduleId;
    }

    public void setFromScheduleId(long fromScheduleId) {
        this.fromScheduleId = fromScheduleId;
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getNote() {
        return note;
    }

    public void setNote(String note) {
        this.note = note;
    }

    public Date getRequestDate() {
        return requestDate;
    }

    public void setRequestDate(Date requestDate) {
        this.requestDate = requestDate;
    }

    public short getStatus() {
        return status;
    }

    public void setStatus(short status) {
        this.status = status;
    }

    public TimeSlot getTimeslot() {
        return timeSlot;
    }

    public void setTimeslot(TimeSlot timeSlot) {
        this.timeSlot = timeSlot;
        this.timeSlotId = timeSlot.getId();
    }

    public Employee getEmployee() {
        return employee;
    }

    public void setEmployee(Employee employee) {
        this.employee = employee;
        this.employeeId = employee.getId();
    }

    public long getEmployeeId() {
        return employeeId;
    }

    public void setEmployeeId(long toScheduleId) {
        this.employeeId = toScheduleId;
    }

    public void loadFromResultSet(ResultSet rs) {
        try {
            TimeSlot requestTimeSlot = null;
            EmployeeSchedule sf = null;
            TimeSlot tsf = null;
            Employee ef = null;
            Roll rf = null;
            EmployeeSchedule st = null;
            TimeSlot tst = null;
            Employee et = null;
            Roll rt = null;

            rf = new Roll(rs.getLong("rf_id"), rs.getString("rf_name"), rs.getBoolean("rf_head"));
            rt = new Roll(rs.getLong("rt_id"), rs.getString("rt_name"), rs.getBoolean("rt_head"));
            ef = new Employee(rs.getLong("ef_id"), rs.getString("ef_username"), rs.getString("ef_first_name"), rs.getString("ef_last_name"), rs.getBoolean("ef_gender"), rf);
            et = new Employee(rs.getLong("et_id"), rs.getString("et_username"), rs.getString("et_first_name"), rs.getString("et_last_name"), rs.getBoolean("et_gender"), rt);
            tsf = new TimeSlot(rs.getLong("tsf_id"), rs.getTime("tsf_from"), rs.getTime("tsf_to"));
            sf = new EmployeeSchedule(rs.getLong("sf_id"), rs.getDate("sf_date"), ef, tsf);
            requestTimeSlot = new TimeSlot(rs.getLong("request_time_slot_id"), rs.getTime("request_from"), rs.getTime("request_to"));

            this.setId(rs.getLong("id"));
            this.setNote(rs.getString("request_note"));
            this.setStatus(rs.getShort("request_status"));
            this.setRequestDate(rs.getDate("request_date"));
            this.setTimeslot(requestTimeSlot);
            this.setFromSchedule(sf);
            this.setEmployee(et);
        } catch (SQLException ex) {
            Logger.getLogger(EmployeeShiftRequest.class.getName()).log(Level.SEVERE, null, ex);
        }

    }
}
